﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightClientLibrary.Messages
{
    public abstract class StringMessage : BigMessage
    {
        protected string _string;

        public StringMessage(string s) : base() { _string = s; }

        public byte[] EncodeString()
        {
            byte[] b = System.Text.Encoding.Unicode.GetBytes(_string);
            byte[] retArr = new byte[this.BufferSize];
            retArr[0] = (byte)Enum.Parse(typeof(MessageId), this.GetType().ToString().Remove(0, this.GetType().ToString().LastIndexOf('.') + 1), true);
            retArr[2] = (byte)b.Length;
            b.CopyTo(retArr, 3);
            return retArr;
        }

        public override Message Decode(byte[] bytes)
        {
            _string = System.Text.Encoding.Unicode.GetString(bytes, 3, bytes[2]);
            return this;
        }
    }
}
